import java.sql.*;

public class jdbc {

    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
	static final String DB_URL = "jdbc:mysql://localhost:3306/site1";

	static final String user = "ccq";
    static final String pass = "12345";
    
    public static void main(String[] args)
    {
        Connection conn = null;
        Statement stmt = null;

        try{
            //register JDBC Driver
            Class.forName(JDBC_DRIVER);

            //open url
            System.out.println("Connencting DB ...");

            conn = DriverManager.getConnection(DB_URL, user, pass);

            stmt = conn.createStatement();
            String sql;
            sql = "SELECT id, name, url FROM websites";
            ResultSet rs = stmt.executeQuery(sql);

            while(rs.next())
            {
                int id = rs.getInt("id");
                String name = rs.getString("name");
                String url = rs.getString("url");

                System.out.print("ID: " + id);
                System.out.print(" SiteName: " + name);
                System.out.print(" URL: " + url + "\n");
                
            }

            rs.close();
            stmt.close();
            conn.close();
        }
        catch(SQLException se)
        {
            se.printStackTrace();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        finally{
            try{
                if(stmt != null)
                    stmt.close();
                
            }
            catch(SQLException se2)
            {

            }

            try{
                if(conn != null)
                    conn.close();
                
            }
            catch(SQLException se3){

            }
        }

        System.out.println("Goodbuy!");
    }
    
}
